//============================================================================
// Name        : ocp1.cpp
// Author      : Fangang
// Version     :
// Copyright   : easydev
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

class Command {
public:
	virtual ~Command() {}
	virtual void perform()=0;
};

class ChkBuffer: public Command {
public:
	void perform() {
		cout << "check the buffer" << endl;
	}
};

class ChkIc: public Command  {
public:
	void perform() {
		cout << "check the IC card" << endl;
	}
};

class ChkCard: public Command  {
public:
	void perform() {
		cout << "check the card" << endl;
	}
};

class QueryStats: public Command  {
public:
	void perform() {
		cout << "query the statistic" << endl;
	}
};

class Factory {
private:
	Factory();
public:
	static Factory* getInstance() {
		static Factory* instance;
		return instance;
	}
	Command* create(string cmd) {
		if(cmd=="chkBuffer") return new ChkBuffer();
		if(cmd=="chkIc") return new ChkIc();
		if(cmd=="chkCard") return new ChkCard();
		if(cmd=="queryStats") return new QueryStats();
		return NULL;
	}
};

class Client {
private:
public:
	void perform(string cmd) {
		Factory* factory = Factory::getInstance();
		cout << ">>>cmd: " << cmd << endl;
		Command* command = factory->create(cmd);
		command->perform();
	}
};


int main() {
	Client* client = new Client();
	string cmd;
	cmd = "chkBuffer";
	client->perform(cmd);
	cmd = "chkIc";
	client->perform(cmd);
	cmd = "chkCard";
	client->perform(cmd);
	cmd = "queryStats";
	client->perform(cmd);
}
